package edu.ccut.saturn.basecomponent.database.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import edu.ccut.saturn.basecomponent.database.ISaturnSQL;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnData;

/**
 * 常规SQL执行器
 * 
 * @author tony
 * 
 */
public class SaturnSimpleSQLHandler extends AbstractSQLHandler {

	public List<SaturnData> executeQuery(ISaturnSQL saturnSQL, Connection conn)
			throws SaturnComponentException {
		return null;
	}

	public int executeUpdate(ISaturnSQL saturnSQL, Connection connection)
			throws SaturnComponentException {

		if (connection != null) {
			Statement statement = null;

			try {
				statement = connection.createStatement();
				debug("UPDATE_SQL = " + saturnSQL.getSql());
				return statement.executeUpdate(saturnSQL.getSql());
			} catch (SQLException e) {
				throw new SaturnComponentException(e);
			} finally {
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		} else {
			throw new SaturnComponentException("Connection is null");
		}

	}
}
